﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加会员-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="weadmin-body">
        <form class="layui-form">
            <input type="hidden" id="EPTID" name="EPTID" />
            <div class="layui-form-item">
                <label for="EPTName" class="layui-form-label">
                    <span class="we-red">*</span>类型名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="EPTName" name="EPTName" lay-verify="required" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="EPTOrder" class="layui-form-label">
                    排序顺序
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="EPTOrder" name="EPTOrder" lay-verify="required|number" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="EPTDescribe" class="layui-form-label">
                    类型描述
                </label>
                <div class="layui-input-block">
                    <textarea id="EPTDescribe" name="EPTDescribe" placeholder="请输入" class="layui-textarea" autocomplete="off"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="add">确定</button>
                </div>
            </div>
        </form>
    </div>
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../static/js/common.js" charset="utf-8"></script>

    <script>
        layui.use(['form', 'jquery', 'layer'], function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer;
            $.support.cors = true;
            $.ajaxSetup({
                cache: false,
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
            })
            $(function () {
                //加载试卷类型信息
                var editdata = {};
                var infoajax = $.ajax({
                    url: ApiUrl + "ExamPaperType",
                    type: 'get',
                    data: { id: getUrlParam("ID") },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            editdata = data.Data;
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                //相关ajax加载完成后，绑定数据
                $.when(infoajax)
                    .done(function () {
                        for (var key in editdata) {
                            $("#" + key).val($.trim(editdata[key]));
                        }
                        form.render();
                    })
                    .fail(function () {
                    });
            })
            //监听提交
            form.on('submit(add)', function (formdata) {
                $.ajax({
                    url: ApiUrl + "ExamPaperType/Edit",
                    type: 'post',
                    data: formdata.field,
                    success: function (data) {
                        console.log(data)
                        if (data.StatusCode == 200 && data.Count != 0) {
                            layer.alert("编辑成功", { icon: 6 }, function (index) {
                                parent.layer.closeAll();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                return false;
            });
        });
    </script>
</body>
</html>